/*
 * JBeagle - a Java toolkit for genetic algorithms.
 * 
 * Copyright (c) 2010 Matthijs Snel
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package jbeagle.config;

import java.util.Collections;
import java.util.Map;
import java.util.HashMap;

public class Configuration {
	
	protected Map<String, Configuration> nodes;
	protected Map<String, String> values;
	protected Map<String, Object> objects;
	private String name;
	
	public Configuration( String name ) {
		nodes = new HashMap<String, Configuration>();
		values = new HashMap<String, String>();
		objects = new HashMap<String, Object>();
		this.name = name;
	}
	
	public void addConfig( String tag, Configuration c ) {
		nodes.put(tag, c);
	}
	
	public void addObject( String tag, Object o ) {
		objects.put(tag, o);
	}
	
	public void addValue( String tag, String value ) {
		values.put(tag, value);
	}
	
	public Configuration getConfig(String tag) {
		return nodes.get(tag);
	}
	
	public Map<String, Configuration> getConfigs() {
		return Collections.unmodifiableMap( nodes );
	}
	
	public boolean getBoolean(String tag) {
		return Boolean.parseBoolean(values.get(tag));
	}
	
	public double getDouble(String tag) {
		return Double.parseDouble(values.get(tag));
	}
	
	public int getInt(String tag) {
		return Integer.parseInt(values.get(tag));
	}
	
	public String getName() {
		return name;
	}
	
	public Object getObject( String tag ) {
		return objects.get(tag);
	}
	
	public Map<String, Object> getObjects() {
		return Collections.unmodifiableMap(objects);
	}
	
	public String getString(String tag) {
		return values.get(tag);
	}
	
	public Map<String, String> getValues() {
		return Collections.unmodifiableMap(values);
	}
}

